<?php
 /**
 * 功能描述：	通用
 * @datetime	2022-07-23
 * @version   	v1.0
 * @author   	ZHL
 * @copyrigh  	2022 ZHL 版权所有
 */

class C_CommonServe extends Model {
    /**
     * Notes:新增文件上传日志
     * User: ZhuHaili
     * Date: 2020/3/24
     * @param $paths
     * @return bool
     */
    function addFileLog($paths){
        if(!$paths){
            return false;
        }
        $createdate = date('Y-m-d  H:i:s');
        $data['createdate'] = $createdate;
        $data['title'] = $paths;
        $commonM = new C_CommonModel();
        return $commonM->addFileLog($data);
    }

    /**
     * Notes: 查询文件上传日志
     * User: ZhuHaili
     */
    function getFileLog($status){
        $sql['table'] = 'syslog_file';
        $sql['where'] = " and status='$status'";
        return $this->conn('mysql')->select($sql);
    }

    /**
     * Notes: 修改删除标识
     * User: ZhuHaili
     */
    function updataFileLogDelflag($filePath){
        if(!$filePath){
            return false;
        }
        $sql['table'] = 'syslog_file';
        $sql['where']['title'] = $filePath;
        return $this->conn('mysql')->del($sql);
    }

    /**
     * Notes:修改文件日志标识状态
     * User: ZhuHaili
     * Date: 2023/2/24
     */
    public function updateFileLogStatus($filePath, $status){
        if(!$filePath){
            return false;
        }
        $filePath = Fun::trimStr($filePath); // 去除空白换行符等
        if(!in_array($status,array(1,2))){
            return false;
        }
        return $this->conn('mysql')->updateData('syslog_file', array('status'=>$status), array('title'=>$filePath));
    }

    /**
     * Notes:参数匹配字段找出图片/文件上传的字段
     * User: ZhuHaili
     */
    public function getParamFieldFileType($fields, $param){
        $data = array();
        foreach($fields as $k=>$v){
            $field = $v['fieldcode'];
            // 字段存在数组中时
            if(array_key_exists($field, $param)){
                // 为图片/文件上传类型时
                if(in_array($v['fieldtype'], array(13,14,15,16,17))){
                    $data[] = $field;
                }
            }
        }
        return $data;
    }
}